import pygame
from character import Character
from math import sin,cos

class Paddle(Character):
    # 构造函数
    def __init__(self, screen):
        # 调用父类的构造函数
        super().__init__(screen)

    # 根据面向方向移动(重写)
    def move_by_direction(self, distance):
        # 判断球拍的左边缘碰到屏幕边缘时，或者 球拍的右边缘碰到屏幕边缘时，不能再往左移动
        if (self.x <= 0):
            self.set_position(1, self.y)
            return False
        
        if (self.x + self.width * self.size >= self.screen.get_width()):
            self.set_position(self.screen.get_width() - self.width * self.size - 1, self.y)
            return False

        # 根据distance,self.direction的方向计算x,y的移动距离
        distance_x = distance * cos(self.direction * 3.14 / 180)
        distance_y = -distance * sin(self.direction * 3.14 / 180)
        # 移动
        self.move(distance_x, distance_y)